package com.xhu.service.impl;

import com.xhu.dao.UserMapper;
import com.xhu.entity.User;
import com.xhu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserInfo(int userId) {
        User user = userMapper.selectByPrimaryKey(userId);

        return user;
    }

    @Override
    public User checkUserInfo(User userInfo) {
        User user = userMapper.checkUserInfo(userInfo);
        return user;
    }

    @Override
    public boolean checkUserAccount(String userAccount) {
        Boolean result = false;
        //通过用户账号查找用户信息
        User user = userMapper.checkUserAccount(userAccount);

        if (user != null && user.getUserAccount() != null){
            result = true;
        }

        return result;
    }

    @Override
    public boolean register(User user) {
        boolean result = false;
        //数据库插入用户信息
        int id = userMapper.insertSelective(user);

        if(id > 0){
            result = true;
        }
        return result;
    }
}
